#ifndef STREAM_HANDLE_H_
#define STREAM_HANDLE_H_

struct bufferevent;
struct event_base;

#include <string>
#include <cstdio>

class StreamService;

/// @brief 文件传输处理类
class StreamHandle
{
public:
    StreamHandle(int socket, StreamService *parent);
    virtual ~StreamHandle();
    void ReadCb();
    void WriteCb();
    void EventCb(short which);
    bool Response(const char *header, int header_size, const char *data, int data_size);
    void SendFile();
    void Launch();

private:
    void ProtoBufRead();
    void ByteStreamRead();
    StreamService *parent_ = nullptr;
    event_base *eb_ = nullptr;
    bufferevent *bev_ = nullptr;
    int socket_;
    bool is_stream_;
    int file_size_;
    int remain_size_;
    std::string file_name_;
    std::string signature_;
    FILE *pf_ = nullptr;
    unsigned int send_id_;
    unsigned int recv_id_;
};

#endif